home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.db.net;
-
- import java.io.IOException;
- import java.io.InputStream;
- import symjava.sql.SQLException;
-
- public final class SocketIS extends InputStream {
- private byte[] data;
- private int length;
- private int offset;
- InputStream _istrm;
- byte[] _header;
- int _msgnum;
- boolean bClosed = false;
- MPlex _mplex;
-
- public SocketIS(InputStream istrm, MPlex mplex) throws SQLException {
- this._mplex = mplex;
- this.length = 0;
- this.offset = 0;
- this._istrm = istrm;
- this._header = new byte[5];
- }
-
- public void close() throws IOException {
- this._istrm.close();
- this.bClosed = true;
- }
-
- public int read() throws IOException {
- if (this.offset >= this.length) {
- try {
- this.data = this.getData();
- this.length = this.data.length;
- if (this.length == 0) {
- this.close();
- return -1;
- }
-
- this.offset = 0;
- } catch (SQLException e) {
- throw new IOException(((Throwable)e).getMessage());
- }
- }
-
- return this.data[this.offset++] & 255;
- }
-
- byte[] getData() throws SQLException {
- short streamID = (short)32767;
-
- try {
- int lenRecv = 0;
-
- for(int npass = 0; lenRecv < 5 && npass < 4; ++npass) {
- lenRecv += this._istrm.read(this._header, lenRecv, 5 - lenRecv);
- }
-
- if (this._header[0] != -69) {
- throw new SQLException("Ivalid Packet header");
- } else {
- int msglen = this._header[2];
- if (msglen < 0) {
- msglen += 256;
- }
-
- msglen += (this._header[1] << 8) - 2;
- streamID = (short)this._header[4];
- if (streamID < 0) {
- streamID += 256;
- }
-
- streamID = (short)(streamID + (this._header[3] << 8));
- int ipos = 0;
-
- byte[] msgbufRecv;
- for(msgbufRecv = new byte[msglen]; msglen > 0; ipos += lenRecv) {
- lenRecv = this._istrm.read(msgbufRecv, ipos, msglen);
- msglen -= lenRecv;
- }
-
- return msgbufRecv;
- }
- } catch (IOException var7) {
- this._mplex.connectionLost();
- throw new SQLServerConnException();
- }
- }
-
- public void reset() {
- this.length = 0;
- this.offset = 0;
- }
- }
-